package hello;

import hello.entity.Student;
import hello.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class Run {
    public static void main(String[] args) {
        String resource = "mybatis-cfg.xml";
        InputStream inputStream;
        try {
            inputStream = Resources.getResourceAsStream(resource);

            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

            SqlSession sqlSession = sqlSessionFactory.openSession();

            StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
            Student student = mapper.selectOneById(1L);
            System.out.println(student);

            sqlSession.close();
        } catch (IOException e){
            e.printStackTrace();
        }
    }
}
